package com.qianyu.project.web.controller.wyh;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qianyu.project.entity.Bank;
import com.qianyu.project.entity.SubcontractPayment;
import com.qianyu.project.service.IBankService;
import com.qianyu.project.service.ISubcontractPaymentService;
import com.qianyu.project.utils.Result;
import com.qianyu.project.utils.ResultTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.Map;

/**
 * author wyh
 * Date 2021/2/10
 **/
@RestController
@RequestMapping("WyhBanks")
public class WyhProgressPaymentController {

    @Autowired
    private IBankService iBankService;

    @Autowired
    private ISubcontractPaymentService iSubcontractPaymentService;

    @GetMapping
    public Result list(@RequestParam Map<String,Object> map){
        System.out.println(map);
        QueryWrapper<Bank> qw = new QueryWrapper();
        qw.eq(!StringUtils.isEmpty(map.get("Name")),"bank_name",map.get("Name"));
        return ResultTool.success(iBankService.list(qw));
    }

    @GetMapping("/code")
    public Result getMaxCode() {
        return ResultTool.success(Long.parseLong(iSubcontractPaymentService.getMaxCode()) + 1);
    }

    @PostMapping("")
    public Result addLaborSubcontract(@RequestBody Map<String,Object> map){
        SubcontractPayment sp = new SubcontractPayment();
        sp.setFkId((Integer) map.get("fkId"));
        sp.setPId((Integer) map.get("pId"));
        sp.setConId((Integer) map.get("conId"));
        sp.setProId((Integer) map.get("proId"));
        sp.setPaymentName( map.get("paymentName").toString());
        sp.setContractAmount((BigDecimal) map.get("contractAmount"));
        sp.setSettleComment( map.get("paymentName").toString());
        sp.setAgreeAmount((BigDecimal) map.get("agreeAmount"));
        sp.setAgreeUpper( map.get("agreeUpper").toString());
        sp.setPenalty((BigDecimal) map.get("penalty"));
        sp.setWithhold((BigDecimal) map.get("withhold"));
        sp.setEId((Integer) map.get("eId"));
        sp.setApproveStatus(1);
        sp.setFkAmount((BigDecimal) map.get("fkAmount"));
        sp.setFkType( map.get("fkType").toString());
        sp.setBId((Integer) map.get("bankId"));
        sp.setYhzh( map.get("bankOfDeposit").toString());
        sp.setAttachIds( map.get("attachIds").toString());
        sp.setComment( map.get("comment").toString());
        sp.setUpdateDate( map.get("updateDate").toString());
        iSubcontractPaymentService.saveOrUpdate(sp);
        return ResultTool.success();
    }

    @GetMapping("/list")
    public Result getSubcontracts(@RequestParam Map<String,Object> map){

        return ResultTool.success(iSubcontractPaymentService.getSubcontracts(map));
    }
}
